﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;

namespace Zendesk.NET.Models
{
    [XmlRoot(ElementName = "ticket", Namespace = "")]
    public class Ticket
    {
        [XmlElement("assigned-at")]
        public DateTime? Assigned;

        [XmlElement("assignee-id")]
        public int? AssigneeId { get; set; }

        [XmlElement("base-score")]
        public int BaseScore;

        [XmlElement("created-at")]
        public DateTime Created;

        [XmlElement("current-collaborators")]
        public string Collaborators;

        [XmlElement("current-tags")]
        public string Tags;

        [XmlElement("description")]
        public string Description;

        [XmlElement("due-date")]
        public DateTime? DueDate;

        [XmlElement("entry-id")]
        public int? EntryId { get; set; }

        [XmlElement("external-id")]
        public string ExternalId;

        [XmlElement("group-id")]
        public int GroupId;

        [XmlElement("initially-assigned-at")]
        public DateTime? InitiallyAssigned;

        [XmlElement("latest-recipients")]
        public string LatestRecipients;

        [XmlElement("nice-id")]
        public int NiceId;

        [XmlElement("organization-id")]
        public int? OrganizationId { get; set; }

        [XmlElement("original-recipient-address")]
        public string OriginalRecipientId;

        [XmlIgnore]
        public Priority Priority { get; set; }

        [XmlElement("priority-id")]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public int XmlPriority { get { return (int)Priority; } set { Priority = (Priority)value; } }

        [XmlElement("recipient")]
        public string Recipient;

        [XmlElement("requester-id")]
        public int RequesterId;

        [XmlElement("resolution-time")]
        public int? ResolutionTime { get; set; }

        [XmlElement("solved-at")]
        public DateTime? Solved;

        [XmlIgnore]
        public Status Status { get; set; }

        [XmlElement("status-id")]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public int XmlStatus { get { return (int)Status; } set { Status = (Status)value; } }

        [XmlElement("status-updated-at")]
        public DateTime StatusUpdated;

        [XmlElement("subject")]
        public string Subject;

        [XmlElement("submitter-id")]
        public int SubmitterId;

        [XmlIgnore]
        public Type TicketType { get; set; }

        [XmlElement("ticket-type-id")]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public int XmlTicketType { get { return (int)TicketType; } set { TicketType = (Type)value; } }

        [XmlElement("updated-at")]
        public DateTime Updated;

        [XmlIgnore]
        public Via Via { get; set; }

        [XmlElement("via-id")]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public int XmlVia { get { return (int)Via; } set { Via = (Via)value; } }

        [XmlElement("score")]
        public int Score;

        [XmlElement("problem-id")]
        public int? Problem { get; set; }

        [XmlElement("has-incidents")]
        public bool HasIncidents;

        [XmlArray("linkings")]
        [XmlArrayItem("link")]
        public List<Link> Links;

        [XmlArray("ticket-field-entries")]
        [XmlArrayItem("ticket-field-entry")]
        public List<TicketField> TicketFields;

        [XmlArray("comments")]
        [XmlArrayItem("comment")]
        public List<Comment> Comments;

        [XmlElement("channel")]
        public string Channel;

        //[XmlIgnore]
        //public Lazy<User> User = new Lazy<User>(() => new User());



    }

    public enum Status
    {
        New = 0,
        Open = 1,
        Pending = 2,
        Solved = 3,
        Closed = 4
    }

    public enum Type
    {
        NotSet = 0,
        Question = 1,
        Incident = 2,
        Problem = 3,
        Task = 4
    }

    public enum Priority
    {
        NotSet = 0,
        Low = 1,
        Normal = 2,
        High = 3,
        Urgent = 4
    }

    public enum Via
    {
        WebForm = 0,
        Mail = 4,
        WebServiceApi = 5,
        GetSatisfaction = 16,
        Dropbox = 17,
        TicketMerge = 19,
        RecoveryFromSuspendedTicket = 21,
        TwitterFavorite = 23,
        ForumTopic = 24,
        TwitterDirectMessage = 26,
        ClosedTicket = 27,
        Chat = 29,
        TwitterPublicMention = 30,
        VoiceMail = 33
    }
}